function [LE,MU]=eigl(W,nb);

% subroutine to undertake the following tasks:
%  (1) compute the left eigenvalues and eignvectors of W,
%      allowing the user to specify whether the eigenvalues
%      are balanced or not;
%  (2) reorder the eigenvalues and eigenvectors so that the
%      the eigenvalues occur in diminsising absolute value.

% There default is to compute balanced eigenvalues (nb=0)

if (nargin<2)
   nb=0;
end

% The MATLAB program eig.m computes the right eigenvectors of W, so
% we begin by specifying how to use this code to find left eigenvectors.

% The right eigenvectors of W are a matrix RE such that W*RE=RE*MU
% The left eigenvectors of W are a matrix LE such that LE*W=MU*LE
% where in each case MU is the diagonal matrix of eigenvalues.  Thus,
% taking the transpose of LE*W=MU*LE, we find that W'*LE'=LE'*MU'=LE'*MU
% where the last equality stems from the fact that MU is diagonal. Thus,
% the left eigenvectors of W can be found by computing the right 
% eigenvectors of W' and then transposing the result.

% Compute the left eigenvectors of W'.

if (nb==1)
   [LE MU]=eig(W','nobalance');
else
   [LE MU]=eig(W');
end

LE=LE';
MU=MU';

% Order the eigenvalues of W from highest to lowest in absolute value

mu=diag(MU);

nw=cols(W);

[mun ord]=sort(abs(mu));  % eigenvalues sorted in ascending absolute value

rev=nw:-1:1;
ord=ord(rev);  % reverse ordering so descending absolute value

MU=diag(mu(ord));

LE=LE(ord,:);
